﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using itau.im.entidade;
using EnterpriseLibraryWrapper;
using System.Data;

namespace itau.im.dado
{
    public class ExecucaoCurvaDB : IExecucaoCurvaDAO
    {
        #region Métodos

        public IList<RegistroExecucaoCurva> ObterRegistrosExecucaoCurvaLikeNome(DateTime dataInicio, DateTime dataFim, int codigoTipoCurva, int codigoModalidade, string nomeCurva, int codigoSituacao, int codigoMoeda, int codigoTipoEntradaDado, int codigoSubMesa, int codigoCategoriaMercado)
        {
            List<RegistroExecucaoCurva> listaRetorno = new List<RegistroExecucaoCurva>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WNOM_CURV", nomeCurva, DbType.String));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_CURV", codigoTipoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SUB_MESA_OPER", codigoSubMesa, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CATE_MERC", codigoCategoriaMercado, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_MODA_CURV", codigoModalidade, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", codigoSituacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_ENTR_DAD", codigoTipoEntradaDado, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_MOED", codigoMoeda, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_INIO", dataInicio, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_FIM", dataFim, DbType.DateTime));

                #region Codigo Antigo
                //data.ParameterIn.Add(new ParameterInWrapper("@NOM_CURV", nomeCurva, DbType.String));

                //if (codigoTipoCurva != 0)
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@COD_TIPO_CURV", codigoTipoCurva, DbType.Int16));
                //}
                //else
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@COD_TIPO_CURV", null, DbType.Int16));
                //}

                //if (codigoModalidade != 0)
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@COD_MODA_CURV", codigoModalidade, DbType.Int16));
                //}
                //else
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@COD_MODA_CURV", null, DbType.Int16));
                //}

                //if (dataInicio != DateTime.MinValue)
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@DAT_INI", dataInicio, DbType.DateTime));
                //}
                //else
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@DAT_INI", null, DbType.DateTime));
                //}

                //if (dataFim != DateTime.MinValue)
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@DAT_FIM", dataFim, DbType.DateTime));
                //}
                //else
                //{
                //    data.ParameterIn.Add(new ParameterInWrapper("@DAT_FIM", null, DbType.DateTime));
                //}

                //data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", codigoSituacao, DbType.Int16));

                //ds = data.ExecuteDataSet("DB2IM.IM0S8J");
                #endregion

                ds = data.ExecuteDataSet("DB2IM.IM0SPD");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getRegistroExecucaoCurvaIM0S8J(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<RegistroExecucaoCurva>();
        }

        public void PersistirExecucao(IList<CurvaExecucaoPonto> vertices, RegistroExecucaoCurva registroExecucao)
        {
            IDataAccessWrapper data = null;
            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.BeginTransaction();

                foreach (CurvaExecucaoPonto ponto in vertices)
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", ponto.CodigoCurva, DbType.Int32));
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", ponto.DataInclusaoVigencia, DbType.DateTime));
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", ponto.DataHoraExecucaoCurva, DbType.DateTime));
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_VCTO", ponto.DataVencimento, DbType.Date));

                    if (double.IsInfinity(ponto.ValorVertice) || double.IsNaN(ponto.ValorVertice))
                    {
                        data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", -1, DbType.Double));
                    }
                    else
                    {
                        data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", ponto.ValorVertice, DbType.Double));
                    }

                    data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_CRRI", ponto.QuantidadeDiasCorridos, DbType.Int32));
                    data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_UTIL", ponto.QuantidadeDiasUteis, DbType.Int32));
                    data.ParameterIn.Add(new ParameterInWrapper("@IND_VRTE", ponto.IndicadorVertice, DbType.Int16));

                    data.ExecuteNonQuery("DB2IM.IMSKJ");
                    data.ParameterIn.Clear();
                    data.ParameterOut.Clear();
                }

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", registroExecucao.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", registroExecucao.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", registroExecucao.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", registroExecucao.CodigoSituacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_TIPO_EVEN_NOT", registroExecucao.CodigoTipoEventoNotificacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HORA_LIBE_CURV", registroExecucao.DataHoraLiberacaoCurva, DbType.DateTime));

                data.ExecuteNonQuery("DB2IM.IMSK1");
                data.ParameterIn.Clear();
                data.ParameterOut.Clear();

                data.CommitTransaction();
            }
            catch (DadosException ex)
            {
                data.RollBackTransaction();
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                data.RollBackTransaction();
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public IList<RegistroExecucaoCurva> ObterRegistrosExecucaoCurva(DateTime dataHoraFim, int codigoSituacaoInicio, int codigoSituacaoFim)
        {
            List<RegistroExecucaoCurva> listaRetorno = new List<RegistroExecucaoCurva>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_FIM", dataHoraFim, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU_INI", codigoSituacaoInicio, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU_FIM", codigoSituacaoFim, DbType.Int32));

                ds = data.ExecuteDataSet("DB2IM.IMSER");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getRegistroExecucaoCurvaIMSER(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<RegistroExecucaoCurva>();
        }

        public IList<RegistroExecucaoCurva> ObterRegistrosExecucaoCurvaTransferPrice(DateTime dataHoraFim, int codigoSituacaoInicio, int codigoSituacaoFim)
        {
            List<RegistroExecucaoCurva> listaRetorno = new List<RegistroExecucaoCurva>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_FIM", dataHoraFim, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU_INI", codigoSituacaoInicio, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU_FIM", codigoSituacaoFim, DbType.Int32));

                ds = data.ExecuteDataSet("DB2IM.IM0SZB");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getRegistroExecucaoCurvaIMSER(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<RegistroExecucaoCurva>();
        }

        public IList<RegistroExecucaoCurva> ObterRegistrosExecucaoCurvaPricingBIHF(DateTime dataHoraFim, int codigoSituacaoInicio, int codigoSituacaoFim)
        {
            List<RegistroExecucaoCurva> listaRetorno = new List<RegistroExecucaoCurva>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_FIM", dataHoraFim, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU_INI", codigoSituacaoInicio, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU_FIM", codigoSituacaoFim, DbType.Int32));

                ds = data.ExecuteDataSet("DB2IM.IM0SZC");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getRegistroExecucaoCurvaIMSER(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<RegistroExecucaoCurva>();
        }

        public IList<RegistroExecucaoCurva> ObterRegistrosExecucaoCurva(DateTime dataHoraFim, int codigoSituacaoInicio, int codigoSituacaoFim, int codigoTipoCurva)
        {
            List<RegistroExecucaoCurva> listaRetorno = new List<RegistroExecucaoCurva>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_FIM", dataHoraFim, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU_INI", codigoSituacaoInicio, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU_FIM", codigoSituacaoFim, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_TIPO_CURV", codigoTipoCurva, DbType.Int32));

                ds = data.ExecuteDataSet("DB2IM.IM0S7K");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getRegistroExecucaoCurvaIMSER(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<RegistroExecucaoCurva>();
        }

        public IList<RegistroExecucaoCurva> ObterRegistrosExecucaoCurva(int codigoCurva, DateTime dataHoraExecucao, int codigoSituacao)
        {
            List<RegistroExecucaoCurva> listaRetorno = new List<RegistroExecucaoCurva>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", codigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_EXEO_CURV", dataHoraExecucao, DbType.Date));
                // TODO deixar apenas os parametros acima e consulta por DATE() no db2
                //data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_FIM", dataHoraExecucaoFim, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", codigoSituacao, DbType.Int32));

                ds = data.ExecuteDataSet("DB2IM.IM0S7I");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getRegistroExecucaoCurva(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<RegistroExecucaoCurva>();
        }

        public void AtualizarCurvaExecucaoPontos(IList<CurvaExecucaoPonto> vertices)
        {
            IDataAccessWrapper data = null;

            try
            {
                if (vertices != null && vertices.Count > 0)
                {
                    data = EnterpriseLibraryFactory.GetDataAccess();
                    data.BeginTransaction();

                    foreach (CurvaExecucaoPonto itemCurvaExecucaoPonto in vertices)
                    {
                        data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", itemCurvaExecucaoPonto.CodigoCurva, DbType.Int32));
                        data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", itemCurvaExecucaoPonto.DataInclusaoVigencia, DbType.DateTime));
                        data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", itemCurvaExecucaoPonto.DataHoraExecucaoCurva, DbType.DateTime));
                        data.ParameterIn.Add(new ParameterInWrapper("@DAT_VCTO", itemCurvaExecucaoPonto.DataVencimento, DbType.Date));
                        data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", itemCurvaExecucaoPonto.ValorVertice, DbType.Decimal));
                        data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_CRRI", itemCurvaExecucaoPonto.QuantidadeDiasCorridos, DbType.Int32));
                        data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_UTIL", itemCurvaExecucaoPonto.QuantidadeDiasUteis, DbType.Int32));
                        data.ParameterIn.Add(new ParameterInWrapper("@IND_VRTE", itemCurvaExecucaoPonto.IndicadorVertice, DbType.Int16));

                        data.ExecuteNonQuery("DB2IM.IMSEB");
                        data.ParameterIn.Clear();
                    }
                    data.CommitTransaction();
                }
            }
            catch (DadosException ex)
            {
                data.RollBackTransaction();
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                data.RollBackTransaction();
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public void AtualizarRegistroExecucaoCurva(RegistroExecucaoCurva registroExecucaoCurva)
        {
            IDataAccessWrapper data = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", registroExecucaoCurva.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", registroExecucaoCurva.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_CURV", registroExecucaoCurva.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", registroExecucaoCurva.CodigoSituacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_EVEN_NOT", registroExecucaoCurva.CodigoTipoEventoNotificacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HORA_LIBE_CURV", registroExecucaoCurva.DataHoraLiberacaoCurva, DbType.DateTime));

                data.ExecuteNonQuery("DB2IM.IMSK1");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public void AtualizarSituacaoRegistrosExecucaoCurva(int codigoCurva, DateTime dataExecucao, int codigoSituacaoAtual, int codigoSituacaoNova)
        {
            IDataAccessWrapper data = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", codigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_EXEO_CURV", dataExecucao, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", codigoSituacaoAtual, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU_NOVO", codigoSituacaoNova, DbType.Int32));

                data.ExecuteNonQuery("DB2IM.IM0SAB");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public IList<CurvaExecucaoPonto> ObterCurvaExecucaoPontos(int curvaID, DateTime dataInclusaoVigencia, DateTime dataHoraExecucaoCurva)
        {
            List<CurvaExecucaoPonto> listaRetorno = new List<CurvaExecucaoPonto>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", curvaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HORA_EXEO_CUR", dataHoraExecucaoCurva, DbType.DateTime));

                for (int i = 0; (i < 3 && ds == null); i++)
                {
                    try
                    {
                        ds = data.ExecuteDataSet("DB2IM.IMS45");
                    }
                    catch (Exception ex)
                    {
                        EnterpriseLibraryFactory.GetLogger().Write(0, "ErrosDados", "Erro", ex.Message);
                    }
                }

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getCurvaExecucaoPonto(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<CurvaExecucaoPonto>();
        }

        public IList<CurvaExecucaoPonto> ObterCurvaExecucaoPontosAnaliseRetida(int curvaID, DateTime dataInclusaoVigencia, DateTime dataHoraExecucaoCurva)
        {
            List<CurvaExecucaoPonto> listaRetorno = new List<CurvaExecucaoPonto>();
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", curvaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HORA_EXEO_CUR", dataHoraExecucaoCurva, DbType.DateTime));

                ds = data.ExecuteDataSet("DB2IM.IM0SZW");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getCurvaExecucaoPonto(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<CurvaExecucaoPonto>();
        }

        public DataSet ObterCurvaExecucaoPontosDataSet(int curvaID, DateTime dataInclusaoVigencia, DateTime dataHoraExecucaoCurva, DateTime dataLimite)
        {
            IDataAccessWrapper data = null;
            DataSet ds = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", curvaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HORA_EXEO_CUR", dataHoraExecucaoCurva, DbType.DateTime));

                if (dataLimite != DateTime.MinValue)
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_LIM", dataLimite, DbType.Date));
                }
                else
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_LIM", null, DbType.Date));
                }

                return data.ExecuteDataSet("DB2IM.IM0S8K");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
            }

            return ds;
        }

        public void RemoverCurvaExecucaoPontos(RegistroExecucaoCurva registroExecucaoCurva, int indicadorVertice)
        {
            IDataAccessWrapper data = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", registroExecucaoCurva.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", registroExecucaoCurva.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_CURV", registroExecucaoCurva.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WIND_VRTE", indicadorVertice, DbType.Int16));

                data.ExecuteNonQuery("DB2IM.IMS51");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }


        public RegistroExecucaoCurva ObterRegistroExecucaoCurva(int codCurva, DateTime dataInclusao, DateTime dataReferencia, int codigoSituacao)
        {
            RegistroExecucaoCurva regExecCurv = null;
            IDataAccessWrapper data = null;
            DataSet ds;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", codCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", codigoSituacao, DbType.Int16));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", dataReferencia, DbType.DateTime));
                data.ParameterOut.Add(new ParameterOutWrapper("@COD_TIPO_EVEN_NOT", DbType.Int16, 2));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_LIBE_CURV", DbType.DateTime, 26));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_INCU_VIGE", DbType.DateTime, 26));


                ds = data.ExecuteParameterToDataSet("DB2IM.IM0S6Y");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    regExecCurv = EntidadeFactory.getRegistroExecucaoCurva(ds.Tables[0].Rows[0]);
                }

                return regExecCurv;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                regExecCurv = null;
            }

            return null;
        }

        public RegistroExecucaoCurva ObterUltimaExecucaoCurva(int curvaID, DateTime dataReferencia, int codigoSituacao)
        {
            RegistroExecucaoCurva regExecCurv = null;
            IDataAccessWrapper data = null;
            DataSet ds;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", curvaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", codigoSituacao, DbType.Int16));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_IN", dataReferencia, DbType.DateTime));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_INCU_VIGE", DbType.DateTime, 26));
                data.ParameterOut.Add(new ParameterOutWrapper("@COD_TIPO_EVEN_NOT", DbType.Int16, 2));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_LIBE_CURV", DbType.DateTime, 26));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_EXEO_OUT", DbType.DateTime, 26));

                ds = data.ExecuteParameterToDataSet("DB2IM.IMS5V");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    regExecCurv = EntidadeFactory.getRegistroExecucaoCurvaIMSES(ds.Tables[0].Rows[0]);
                }

                return regExecCurv;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                regExecCurv = null;
            }

            return null;
        }

        public RegistroExecucaoCurva ObterUltimaExecucaoCurva(int codigoCurva, DateTime dataInclusaoVigencia, DateTime dataHoraExecucao, int codigoSituacaoRejeitado)
        {
            RegistroExecucaoCurva regExecCurv = null;
            IDataAccessWrapper data = null;
            DataSet ds;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", codigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_IN", dataHoraExecucao, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU_REJE", codigoSituacaoRejeitado, DbType.Int16));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_EXEO_OUT", DbType.DateTime, 26));
                data.ParameterOut.Add(new ParameterOutWrapper("@COD_SITU", DbType.Int16, 2));
                data.ParameterOut.Add(new ParameterOutWrapper("@COD_TIPO_EVEN_NOT", DbType.Int16, 2));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_LIBE_CURV", DbType.DateTime, 26));

                ds = data.ExecuteParameterToDataSet("DB2IM.IM0S7A");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    regExecCurv = EntidadeFactory.getRegistroExecucaoCurvaIMS7A(ds.Tables[0].Rows[0]);
                }

                return regExecCurv;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                regExecCurv = null;
            }

            return null;
        }

        public RegistroExecucaoCurva ObterUltimaExecucaoCurvaVigente(int curvaID, DateTime dataInclusaoVigencia, DateTime dataReferencia, int codigoSituacao)
        {
            RegistroExecucaoCurva regExecCurv = null;
            IDataAccessWrapper data = null;
            DataSet ds;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", curvaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", codigoSituacao, DbType.Int16));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_IN", dataReferencia, DbType.DateTime));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_INCU_VIGE", DbType.DateTime, 26));
                data.ParameterOut.Add(new ParameterOutWrapper("@COD_TIPO_EVEN_NOT", DbType.Int16, 2));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_LIBE_CURV", DbType.DateTime, 26));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_EXEO_OUT", DbType.DateTime, 26));
                ds = data.ExecuteParameterToDataSet("DB2IM.IMS5V");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    regExecCurv = EntidadeFactory.getRegistroExecucaoCurvaIMSES(ds.Tables[0].Rows[0]);
                }

                return regExecCurv;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                regExecCurv = null;
            }

            return null;
        }

        public RegistroExecucaoCurva ObterRegistroExecucaoCurva(int codigoCurva, DateTime dataInclusaoVigencia)
        {
            IDataAccessWrapper data = null;
            RegistroExecucaoCurva registroExecucaoCurva;
            IDataReader dr;

            try
            {
                registroExecucaoCurva = new RegistroExecucaoCurva();

                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", codigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", DBNull.Value, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_IN", DateTime.Now, DbType.DateTime));

                dr = data.ExecuteReader("DB2IM.IMSES");

                registroExecucaoCurva = EntidadeFactory.getRegistroExecucaoCurva(dr);

                return registroExecucaoCurva;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                registroExecucaoCurva = null;
                dr = null;
            }

            return new RegistroExecucaoCurva();
        }

        public void CriarRegistroExecucaoCurva(RegistroExecucaoCurva registroExecucaoCurva)
        {
            IDataAccessWrapper data = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", registroExecucaoCurva.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", registroExecucaoCurva.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", registroExecucaoCurva.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", registroExecucaoCurva.CodigoSituacao, DbType.Int32));

                if (registroExecucaoCurva.CodigoTipoEventoNotificacao != 0)
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@COD_TIPO_EVEN_NOT", registroExecucaoCurva.CodigoTipoEventoNotificacao, DbType.Int32));
                }
                else
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@COD_TIPO_EVEN_NOT", DBNull.Value, DbType.Int32));
                }

                if (registroExecucaoCurva.DataHoraLiberacaoCurva != DateTime.MinValue)
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_LIBE_CURV", registroExecucaoCurva.DataHoraLiberacaoCurva, DbType.DateTime));
                }
                else
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_LIBE_CURV", DBNull.Value, DbType.DateTime));
                }

                data.ExecuteNonQuery("DB2IM.IMSKI");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public void CriarCurvaExecucaoPonto(CurvaExecucaoPonto listaCurvaExecucaoPonto)
        {
            IDataAccessWrapper data = null;
            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", listaCurvaExecucaoPonto.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", listaCurvaExecucaoPonto.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", listaCurvaExecucaoPonto.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_VCTO", listaCurvaExecucaoPonto.DataVencimento, DbType.Date));

                if (double.IsInfinity(listaCurvaExecucaoPonto.ValorVertice) || double.IsNaN(listaCurvaExecucaoPonto.ValorVertice))
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", -1, DbType.Double));
                }
                else
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", listaCurvaExecucaoPonto.ValorVertice, DbType.Double));
                }

                data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_CRRI", listaCurvaExecucaoPonto.QuantidadeDiasCorridos, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_UTIL", listaCurvaExecucaoPonto.QuantidadeDiasUteis, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@IND_VRTE", listaCurvaExecucaoPonto.IndicadorVertice, DbType.Int16));

                data.ExecuteNonQuery("DB2IM.IMSKJ");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }
        /// <summary>
        /// Criar Lista de Execução Ponto utilizando transação.
        /// </summary>
        /// <param name="listaCurvaExecucaoPonto"></param>
        public void CriarCurvaExecucaoPontos(IList<CurvaExecucaoPonto> vertices)
        {
            IDataAccessWrapper data = null;
            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                foreach (CurvaExecucaoPonto ponto in vertices)
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", ponto.CodigoCurva, DbType.Int32));
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", ponto.DataInclusaoVigencia, DbType.DateTime));
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", ponto.DataHoraExecucaoCurva, DbType.DateTime));
                    data.ParameterIn.Add(new ParameterInWrapper("@DAT_VCTO", ponto.DataVencimento, DbType.Date));

                    if (double.IsInfinity(ponto.ValorVertice) || double.IsNaN(ponto.ValorVertice))
                    {
                        data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", -1, DbType.Double));
                    }
                    else
                    {
                        data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", ponto.ValorVertice, DbType.Double));
                    }

                    data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_CRRI", ponto.QuantidadeDiasCorridos, DbType.Int32));
                    data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_UTIL", ponto.QuantidadeDiasUteis, DbType.Int32));
                    data.ParameterIn.Add(new ParameterInWrapper("@IND_VRTE", ponto.IndicadorVertice, DbType.Int16));

                    data.ExecuteNonQuery("DB2IM.IMSKJ");
                    data.ParameterIn.Clear();
                    data.ParameterOut.Clear();
                }
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public void CriarCurvaExecucaoPontosEmLote(IList<CurvaExecucaoPonto> vertices)
        {
            IDataAccessWrapper data = null;

            try
            {
                if (vertices != null 
                    && vertices.Count > 0)
                {
                    data = EnterpriseLibraryFactory.GetDataAccess();
                    int tamanhoPagina = 600;

                    // Montar chave
                    int codigoCurva = vertices[0].CodigoCurva;
                    DateTime dataHoraExecucao = vertices[0].DataHoraExecucaoCurva;
                    DateTime dataInclusaoVigencia = vertices[0].DataInclusaoVigencia;

                    // Inicialização da paginação
                    long resto;
                    int paginas = vertices.Count / tamanhoPagina;
                    Math.DivRem(vertices.Count, tamanhoPagina, out resto);

                    for (int i = 0; i < paginas; i++)
                    {
                        StringBuilder valores = MontarRegistro(vertices, (i * tamanhoPagina), ((i + 1) * tamanhoPagina));

                        bool ultimaPagina = ((resto == 0) && (i == (paginas - 1)));

                        ExecutarCriarPontoEmLote(data, tamanhoPagina, codigoCurva, dataHoraExecucao, dataInclusaoVigencia, ultimaPagina, valores);
                    }

                    if (resto > 0)
                    {
                        StringBuilder valores = MontarRegistro(vertices, (paginas * tamanhoPagina), vertices.Count);

                        ExecutarCriarPontoEmLote(data, Convert.ToInt32(resto), codigoCurva, dataHoraExecucao, dataInclusaoVigencia, true, valores);
                    }
                }
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        private StringBuilder MontarRegistro(IList<CurvaExecucaoPonto> vertices, int valorInicial, int valorLimite)
        {
            StringBuilder valores = new StringBuilder();
            for (int j = valorInicial; j < valorLimite; j++)
            {
                if (vertices[j].ValorVertice.Equals(Double.NaN))
                    vertices[j].ValorVertice = 0;

                valores.Append(string.Format("{0}{1}{2}{3}{4}", vertices[j].DataVencimento.ToString("ddMMyyyy"), FormatarDecimal(vertices[j].ValorVertice), vertices[j].QuantidadeDiasCorridos.ToString().PadLeft(9, '0'), vertices[j].QuantidadeDiasUteis.ToString().PadLeft(9, '0'), vertices[j].IndicadorVertice.ToString().PadLeft(4, '0')));
            }
            return valores;
        }

        private void ExecutarCriarPontoEmLote(IDataAccessWrapper data, int tamanhoPagina, int codigoCurva, DateTime dataHoraExecucao, DateTime dataInclusaoVigencia, bool ultimaPagina, StringBuilder valores)
        {
            data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", codigoCurva, DbType.Int32));
            data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
            data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", dataHoraExecucao, DbType.DateTime));

            data.ParameterIn.Add(new ParameterInWrapper("@QTDE_OCORR", tamanhoPagina, DbType.Int16));

            if (ultimaPagina)
            {
                data.ParameterIn.Add(new ParameterInWrapper("@FLAG_FIM", "S", DbType.String));
            }
            else
            {
                data.ParameterIn.Add(new ParameterInWrapper("@FLAG_FIM", "N", DbType.String));
            }

            //data.ParameterIn.Add(new ParameterInWrapper("@RGTO_DADO", ConverterEmEBCDIC(valores.ToString()), DbType.String));
            data.ParameterIn.Add(new ParameterInWrapper("@RGTO_DADO", valores.ToString(), DbType.String));

            data.ParameterOut.Add(new ParameterOutWrapper("@COD_RET", DbType.Int32, 4));
            data.ParameterOut.Add(new ParameterOutWrapper("@RGTO_ERRO", DbType.Int32, 4));
            data.ParameterOut.Add(new ParameterOutWrapper("@MGS_ERRO", DbType.String, 150));

            data.ExecuteNonQuery("DB2IM.IM0SPN");

            TratarRetorno(data);

            data.ParameterIn.Clear();
            data.ParameterOut.Clear();
        }

        public void CriarCurvaExecucaoPontosEmLote(IList<CurvaExecucaoPonto> vertices, string nomeProcedure)
        {
            IDataAccessWrapper data = null;

            try
            {
                if (vertices != null
                    && vertices.Count > 0)
                {
                    data = EnterpriseLibraryFactory.GetDataAccess();
                    int tamanhoPagina = 600;

                    // Montar chave
                    int codigoCurva = vertices[0].CodigoCurva;
                    DateTime dataHoraExecucao = vertices[0].DataHoraExecucaoCurva;
                    DateTime dataInclusaoVigencia = vertices[0].DataInclusaoVigencia;

                    // Inicialização da paginação
                    long resto;
                    int paginas = vertices.Count / tamanhoPagina;
                    Math.DivRem(vertices.Count, tamanhoPagina, out resto);

                    for (int i = 0; i < paginas; i++)
                    {
                        StringBuilder valores = MontarRegistro(vertices, (i * tamanhoPagina), ((i + 1) * tamanhoPagina));

                        bool ultimaPagina = ((resto == 0) && (i == (paginas - 1)));

                        ExecutarCriarPontoEmLote(data, tamanhoPagina, codigoCurva, dataHoraExecucao, dataInclusaoVigencia, ultimaPagina, valores, nomeProcedure);
                    }

                    if (resto > 0)
                    {
                        StringBuilder valores = MontarRegistro(vertices, (paginas * tamanhoPagina), vertices.Count);

                        ExecutarCriarPontoEmLote(data, Convert.ToInt32(resto), codigoCurva, dataHoraExecucao, dataInclusaoVigencia, true, valores, nomeProcedure);
                    }
                }
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        private void ExecutarCriarPontoEmLote(IDataAccessWrapper data, int tamanhoPagina, int codigoCurva, DateTime dataHoraExecucao, DateTime dataInclusaoVigencia, bool ultimaPagina, StringBuilder valores, string nomeProcedure)
        {
            data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", codigoCurva, DbType.Int32));
            data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
            data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", dataHoraExecucao, DbType.DateTime));

            data.ParameterIn.Add(new ParameterInWrapper("@QTDE_OCORR", tamanhoPagina, DbType.Int16));

            if (ultimaPagina)
            {
                data.ParameterIn.Add(new ParameterInWrapper("@FLAG_FIM", "S", DbType.String));
            }
            else
            {
                data.ParameterIn.Add(new ParameterInWrapper("@FLAG_FIM", "N", DbType.String));
            }

            //data.ParameterIn.Add(new ParameterInWrapper("@RGTO_DADO", ConverterEmEBCDIC(valores.ToString()), DbType.String));
            data.ParameterIn.Add(new ParameterInWrapper("@RGTO_DADO", valores.ToString(), DbType.String));

            data.ParameterOut.Add(new ParameterOutWrapper("@COD_RET", DbType.Int32, 4));
            data.ParameterOut.Add(new ParameterOutWrapper("@RGTO_ERRO", DbType.Int32, 4));
            data.ParameterOut.Add(new ParameterOutWrapper("@MGS_ERRO", DbType.String, 150));

            data.ExecuteNonQuery("DB2IM." + nomeProcedure);

            TratarRetorno(data);

            data.ParameterIn.Clear();
            data.ParameterOut.Clear();
        }

        private string ConverterEmEBCDIC(string valor)
        {
            Encoding ascii = Encoding.ASCII;
            //Encoding ebcdic = JonSkeet.Ebcdic.EbcdicEncoding.GetEncoding(1141);

            //byte[] bytes = ascii.GetBytes(valor);

            //byte[] ebcdicBytes = Encoding.Convert(ascii, ebcdic, bytes);

            ////char[] ebcdicChars = new char[ebcdic.GetCharCount(ebcdicBytes, 0, ebcdicBytes.Length)];
            ////ebcdic.GetChars(ebcdicBytes, 0, ebcdicBytes.Length, ebcdicChars, 0);
            ////string ebcdicString = new string(ebcdicChars);
            //string ebcdicString = string.Empty;
            //foreach (byte b in ebcdicBytes)
            //{

            //}

            //return ebcdicString;

            //StringBuilder sb = new StringBuilder();

            //using (System.IO.StringReader inputReader = new System.IO.StringReader(valor))
            //{
            //    using (System.IO.MemoryStream outputWriter =
            //               new System.IO.MemoryStream())
            //    {
            //        // Create an 8K-char buffer
            //        char[] buffer = new char[8192];
            //        int len = 0;

            //        // Repeatedly read into the buffer and then write it out
            //        // until the reader has been exhausted.
            //        while ((len = inputReader.Read(buffer, 0, buffer.Length)) > 0)
            //        {
            //            outputWriter.Write(buffer, 0, len);
            //        }
            //    }
            //}

            StringBuilder sb = new StringBuilder();

            byte[] teste = Encoding.Default.GetBytes(valor);
            byte[] convertido = Convert.FromBase64String(valor);

            byte b = Convert.ToByte("62", 16);

            char c = (char)b;

            //foreach (byte b1 in teste)
            //{
            //    sb.Append((char)b1);
            //}

            return sb.ToString();
        }

        private static void TratarRetorno(IDataAccessWrapper data)
        {
            if (data.ParameterOut[0].ParameterValue != null
                && Convert.ToInt32(data.ParameterOut[0].ParameterValue) < 0)
            {
                throw new DataException(data.ParameterOut[2].ParameterValue.ToString());
            }
        }

        private string FormatarDecimal(double p)
        {
            string[] valores = p.ToString("N10").Replace(".", string.Empty).Split(',');
            return string.Format("+{0}{1}", valores[0].PadLeft(8, '0'), valores[1].PadLeft(10, '0'));

            //Double numberValue = p * Math.Pow(10, 10);
            //return numberValue.ToString(string.Empty.PadLeft(18, '0'));
        }

        public void AlterarExecucaoRemoverPontos(RegistroExecucaoCurva registro)
        {
            IDataAccessWrapper data = null;
            int SITUACAO_EXECUCAO_AGENDADA = 11;
            int SITUACAO_EXECUCAO_UPLOAD = 14;
            int INDICADOR_VERTICE_NAO = 0;
            int INDICADOR_VERTICE_SIM = 1;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();
                data.BeginTransaction();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", registro.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", registro.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_CURV", registro.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", registro.CodigoSituacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_EVEN_NOT", registro.CodigoTipoEventoNotificacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HORA_LIBE_CURV", registro.DataHoraLiberacaoCurva, DbType.DateTime));

                data.ExecuteNonQuery("DB2IM.IMSK1");
                data.ParameterIn.Clear();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", registro.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", registro.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_CURV", registro.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WIND_VRTE", INDICADOR_VERTICE_NAO, DbType.Int16));

                data.ExecuteNonQuery("DB2IM.IMS51");
                data.ParameterIn.Clear();

                if (registro.CodigoSituacao.Equals(SITUACAO_EXECUCAO_AGENDADA)
                    || registro.CodigoSituacao.Equals(SITUACAO_EXECUCAO_UPLOAD))
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CURV", registro.CodigoCurva, DbType.Int32));
                    data.ParameterIn.Add(new ParameterInWrapper("@WDAT_INCU_VIGE", registro.DataInclusaoVigencia, DbType.DateTime));
                    data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_CURV", registro.DataHoraExecucaoCurva, DbType.DateTime));
                    data.ParameterIn.Add(new ParameterInWrapper("@WIND_VRTE", INDICADOR_VERTICE_SIM, DbType.Int16));

                    data.ExecuteNonQuery("DB2IM.IMS51");
                    data.ParameterIn.Clear();
                }

                data.CommitTransaction();
            }
            catch (DadosException ex)
            {
                data.RollBackTransaction();
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                data.RollBackTransaction();
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public void CriarOuAtualizarCurvaExecucaoPonto(CurvaExecucaoPonto listaCurvaExecucaoPonto)
        {
            IDataAccessWrapper data = null;
            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", listaCurvaExecucaoPonto.CodigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", listaCurvaExecucaoPonto.DataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", listaCurvaExecucaoPonto.DataHoraExecucaoCurva, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_VCTO", listaCurvaExecucaoPonto.DataVencimento, DbType.Date));

                if (double.IsInfinity(listaCurvaExecucaoPonto.ValorVertice) || double.IsNaN(listaCurvaExecucaoPonto.ValorVertice))
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", -1, DbType.Double));
                }
                else
                {
                    data.ParameterIn.Add(new ParameterInWrapper("@VLR_PONT", listaCurvaExecucaoPonto.ValorVertice, DbType.Double));
                }

                data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_CRRI", listaCurvaExecucaoPonto.QuantidadeDiasCorridos, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@QTD_DIA_UTIL", listaCurvaExecucaoPonto.QuantidadeDiasUteis, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@IND_VRTE", listaCurvaExecucaoPonto.IndicadorVertice, DbType.Int16));

                data.ExecuteNonQuery("DB2IM.IMS6H");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        public IList<LiberacaoCurva> ObterCurvasPorTipoMesaCategoriaSituacao(int tipoCurvaID, int subMesaID, int categoriaMercadoID, int codigoSituacao)
        {
            IDataAccessWrapper data = null;
            IList<LiberacaoCurva> liberacaoCurva;
            DataSet ds;

            try
            {
                liberacaoCurva = new List<LiberacaoCurva>();

                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_CURV", tipoCurvaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SUB_MESA_OPER", subMesaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CATE_MERC", categoriaMercadoID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", codigoSituacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_INIO", DateTime.Today, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_FIM", DateTime.Now, DbType.DateTime));

                ds = data.ExecuteDataSet("DB2IM.IMS62");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        liberacaoCurva.Add(EntidadeFactory.getLiberacaoCurva(linha));
                    }
                }

                return liberacaoCurva;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                liberacaoCurva = null;
                ds = null;
            }
            return new List<LiberacaoCurva>();
        }

        public IList<LiberacaoCurva> ObterCurvasPorTipoMesaCategoriaSituacaoData(int tipoCurvaID, int subMesaID, int categoriaMercadoID, int codigoSituacao, DateTime dataReferencia)
        {
            IDataAccessWrapper data = null;
            IList<LiberacaoCurva> liberacaoCurva;
            DataSet ds;

            try
            {
                liberacaoCurva = new List<LiberacaoCurva>();

                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_CURV", tipoCurvaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SUB_MESA_OPER", subMesaID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CATE_MERC", categoriaMercadoID, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", codigoSituacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_INIO", dataReferencia.Date, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_FIM", dataReferencia.Date.AddDays(1).AddMilliseconds(-1), DbType.DateTime));

                ds = data.ExecuteDataSet("DB2IM.IMS62");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        liberacaoCurva.Add(EntidadeFactory.getLiberacaoCurva(linha));
                    }
                }

                return liberacaoCurva;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                liberacaoCurva = null;
                ds = null;
            }
            return new List<LiberacaoCurva>();
        }

        public IList<LiberacaoCurva> ObterCurvasParaLiberacaoRejeicaoConsulta(int codigoTipoCurva, int codigoSubMesa, int codigoCategoriaMercado, int codigoModalidade, int codigoSituacao, int codigoMoeda, int codigoTipoEntradaDado, string nomeCurva, DateTime dataHoraInicio, DateTime dataHoraFim)
        {
            IDataAccessWrapper data = null;
            IList<LiberacaoCurva> listaLiberacaoCurva;
            DataSet dsCurvas;
            DataSet dsTaxaPonto;

            try
            {
                listaLiberacaoCurva = new List<LiberacaoCurva>();

                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@WNOM_CURV", nomeCurva, DbType.String));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_CURV", codigoTipoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SUB_MESA_OPER", codigoSubMesa, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_CATE_MERC", codigoCategoriaMercado, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_MODA_CURV", codigoModalidade, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_SITU", codigoSituacao, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_TIPO_ENTR_DAD", codigoTipoEntradaDado, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WCOD_MOED", codigoMoeda, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_INIO", dataHoraInicio, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@WDAT_HOR_EXEO_FIM", dataHoraFim, DbType.DateTime));

                dsCurvas = data.ExecuteDataSet("DB2IM.IM0SPD");

                if (dsCurvas.Tables.Count > 0)
                {
                    foreach (DataRow itemCurva in dsCurvas.Tables[0].Rows)
                    {
                        LiberacaoCurva liberacaoCurva = EntidadeFactory.getLiberacaoCurvaIMSPD(itemCurva);

                        data.ParameterIn.Clear();
                        data.ParameterOut.Clear();

                        data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", liberacaoCurva.CodigoCurva, DbType.Int32));
                        data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", liberacaoCurva.DataInclusaoVigencia, DbType.DateTime));

                        dsTaxaPonto = data.ExecuteDataSet("DB2IM.IMSEK");

                        if (dsTaxaPonto.Tables.Count > 0)
                        {
                            foreach (DataRow itemTaxaPonto in dsTaxaPonto.Tables[0].Rows)
                            {
                                TaxaPontoCurvaVigente taxaPontoCurva = EntidadeFactory.getTaxaPontoCurvaVigente(itemTaxaPonto);

                                if (taxaPontoCurva.CodigoTipoPontoCurva == 4)
                                {
                                    liberacaoCurva.CodigoTipoVertice = taxaPontoCurva.CodigoTipoTaxa;
                                }
                            }
                        }

                        listaLiberacaoCurva.Add(liberacaoCurva);
                    }
                }

                return listaLiberacaoCurva;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                dsCurvas = null;
                dsTaxaPonto = null;
            }
            return new List<LiberacaoCurva>();
        }

        public IList<RegistroExecucaoCurva> ObterRegistrosExecucaoCurvaPorCurvaVigente(int curvaVigenteID)
        {
            List<RegistroExecucaoCurva> listaRetorno = new List<RegistroExecucaoCurva>();
            IDataAccessWrapper data = null;
            DataSet ds;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("WCOD_CURV INTEGER", curvaVigenteID, DbType.Int32));

                ds = data.ExecuteDataSet("DB2IM.IMS1T");

                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow linha in ds.Tables[0].Rows)
                    {
                        listaRetorno.Add(EntidadeFactory.getRegistroExecucaoCurvaIMSER(linha));
                    }
                }

                return listaRetorno;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                ds = null;
                listaRetorno = null;
            }

            return new List<RegistroExecucaoCurva>();
        }

        public RegistroExecucaoCurva ObterRegistroExecucaoCurva(int codigoCurva, DateTime dataInclusaoVigencia, DateTime dataExecucaoCurva)
        {
            IDataAccessWrapper data = null;
            RegistroExecucaoCurva registroExecucaoCurva;
            DataSet ds;

            try
            {
                registroExecucaoCurva = new RegistroExecucaoCurva();

                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@COD_CURV", codigoCurva, DbType.Int32));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_INCU_VIGE", dataInclusaoVigencia, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CURV", dataExecucaoCurva, DbType.DateTime));
                data.ParameterOut.Add(new ParameterOutWrapper("@COD_SITU", DbType.Int16, 2));
                data.ParameterOut.Add(new ParameterOutWrapper("@COD_TIPO_EVEN_NOT", DbType.Int16, 2));
                data.ParameterOut.Add(new ParameterOutWrapper("@DAT_HOR_LIBE_CURV", DbType.DateTime, 10));

                ds = data.ExecuteParameterToDataSet("DB2IM.IMS71");

                if (ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        registroExecucaoCurva = EntidadeFactory.getRegistroExecucaoCurva(dr);
                    }
                }

                return registroExecucaoCurva;
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
                registroExecucaoCurva = null;
                ds = null;
            }
            return new RegistroExecucaoCurva();
        }

        public void CriarAgendamentoDasCurvasAtivas(DateTime dataHoraAtual, int codigoSituacao, int codigoTipoEventoNotificacao, DateTime dataHoraLiberacaoCurva)
        {
            IDataAccessWrapper data = null;

            try
            {
                data = EnterpriseLibraryFactory.GetDataAccess();

                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_EXEO_CUR", dataHoraAtual, DbType.DateTime));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_SITU", codigoSituacao, DbType.Int16));
                data.ParameterIn.Add(new ParameterInWrapper("@COD_TIPO_EVEN_NO", codigoTipoEventoNotificacao, DbType.Int16));
                data.ParameterIn.Add(new ParameterInWrapper("@DAT_HOR_LIBE_CUR", dataHoraLiberacaoCurva, DbType.DateTime));

                data.ExecuteNonQuery("DB2IM.IMS4M");
            }
            catch (DadosException ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            catch (Exception ex)
            {
                EnterpriseLibraryFactory.GetExceptionHandler().HandleException(ex, "ErrosDados");
            }
            finally
            {
                data.Dispose();
                data = null;
            }
        }

        #endregion
    }
}
